layui.use([ 'form'], function() {
    var form = layui.form;
    let $ = layui.$;
    showLogin(true)

    function showLogin(show) {
        if(show) {
            layer.open({
                type: 1, //页面层
                title: '登 录',
                closeBtn: 0,
                skin: 'layui-layer-rim', //加上边框
                area: ['400px', '280px'], //宽高
                content: $("#loginForm")
            });
        } else {
            layer.close(layer.index)
        }
    }

    //监听提交
    form.on('submit(formDemo)', function(data){
        $.ajax({
            dataType: 'json',
            type: 'post',
            data: data.field,
            url: Api.login.login,
            success: function (result, status, xhr) {
                if(result.code == 200) {
                    sessionStorage.setItem(Global.TOKEN_INFO, JSON.stringify(result.data));
                    window.location = 'index.html'
                } else {
                    layer.alert(result.msg)
                }

            },
            error: function(xhr, status, error) {
                layer.alert(xhr.responseJSON.msg)
            }
        })
        return false;
    });


})
